<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>改变文本颜色</title>
    <style>
        #myText {
            cursor: pointer;
        }
    </style>
</head>

<body>
    <p id="myText">点击改变我的颜色</p >
    <script>
        const textElement = document.getElementById('myText');
        textElement.addEventListener('click', function () {
            const randomColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
            textElement.style.color = randomColor;
        });
    </script>
</body>

</html>